import { FC } from 'react';
import { Button, Checkbox, Form, Input } from 'antd';
import { loginApi } from '@/utils/api';
import { history } from 'umi';

const Login: FC = () => {
  const onFinish = async (values: any) => {
    // console.log('Success:', values);
    const res = await loginApi(values);
    console.log(res);
    if (res.status === 0) {
      history.push('/admin');
      localStorage.setItem('token', '123');
      localStorage.setItem('auth', JSON.stringify(res.result[0].auth));
    }
  };
  return (
    <>
      <h2>登录页面</h2>
      <Form
        name="basic"
        labelCol={{ span: 8 }}
        wrapperCol={{ span: 16 }}
        initialValues={{ remember: true }}
        onFinish={onFinish}
        autoComplete="off"
      >
        <Form.Item
          label="Username"
          name="username"
          rules={[{ required: true, message: 'Please input your username!' }]}
        >
          <Input />
        </Form.Item>

        <Form.Item
          label="Password"
          name="password"
          rules={[{ required: true, message: 'Please input your password!' }]}
        >
          <Input.Password />
        </Form.Item>

        <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
          <Button type="primary" htmlType="submit">
            Submit
          </Button>
        </Form.Item>
      </Form>
    </>
  );
};

export default Login;
